﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DATA.Base;
using DATA.BusinessObjects;
using DATA.ManagerObjects;
using NHibernate;

namespace BUS
{
    public class ChiTietMatDoSuDungPhongBUS
    {
        #region Bình - thêm chi tiết doanh thu theo loại phòng
        public static Boolean ThemChiTietMatDoSuDungPhong(Chitietmatdosudungphong ctdttlp)
        {
            Boolean flag = false;
            ISession isession = NHibernateSessionManager.Instance.CreateISession();
            ITransaction iTrans = null;
            try
            {
                iTrans = isession.BeginTransaction();
                isession.Save(ctdttlp);
                iTrans.Commit();
                flag = true;
            }
            catch (Exception ex)
            {
                iTrans.Rollback();
                isession.Close();
                throw new Exception("Lỗi", ex);
            }
            return flag;
        }
        #endregion

        #region Bình - Lấy chi tiết doanh thu theo loại phòng mới nhất
        public static Chitietmatdosudungphong LayChiTietMatDoSuDungPhongMoiNhat()
        {
            Chitietmatdosudungphong ctmdsdp = null;

            IManagerFactory MF = new ManagerFactory();
            IChitietmatdosudungphongManager CTMDSDPM = MF.GetChitietmatdosudungphongManager();

            String hql = "FROM Chitietmatdosudungphong ctmdsdp "
                        + "WHERE length(ctmdsdp.Id) = (Select MAX(length(ctmdsdp.Id)) "
                                                + "from Chitietmatdosudungphong ctmdsdp) "
                        + "ORDER BY ctmdsdp.Id desc";

            IList<Chitietmatdosudungphong> list = CTMDSDPM.GetByQuery(hql);
            if (list.Count > 0)
                ctmdsdp = list[0];
            return ctmdsdp;
        }
        #endregion
    }
}
